package JZ;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname JZ34
 * @Description // https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/ 树 经典
 * @Date 2021/4/21 15:43
 * @Created by yin
 */
public class JZ34 {
    List<List<Integer>> ans=  new ArrayList<>();
    public List<List<Integer>> pathSum(TreeNode root, int target) {
        dfs(root,target,new ArrayList<>());
        return ans;
    }

    public void dfs(TreeNode node,int target,List<Integer> list){
        if(node==null) return;
        target -= node.val;
        list.add(node.val);
        if(node.left==null && node.right==null && target ==0){
            ans.add(new ArrayList<>(list));
        }else{
            dfs(node.left,target,list);
            dfs(node.right,target,list);
        }
        list.remove(list.size()-1);
    }

}
